package main.gui.comp;

import static java.util.Collections.unmodifiableList;

import java.util.Collection;
import java.util.List;

import javax.swing.JList;

import com.google.common.collect.Lists;

public class JListAdv<T> {
  private JList view = new JList();
  private List<T> data = Lists.newLinkedList();

  public void setData(List<T> data) {
    this.data = data;
    updateView();
  }

  public JList getView() {
    return view;
  }

  public List<T> getData() {
    return unmodifiableList(data); //make unmodifiable
  }

  public void removeAll(Collection<? extends T> coll) {
    data.removeAll(coll);
    updateView();
  }

  private void updateView() {
    view.setListData(data.toArray());
  }

}
